package com.dcy.znoa.common.util.pojo;
import com.google.common.base.Strings;

import java.util.List;

import static com.dcy.znoa.common.util.pojo.JsonCommon.*;

/**
 * JsonForList
 * @param <T>
 */
public class JsonForList<T> implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8457037431122637113L;
	private String code;
	private String msg;
	private Integer total;//分页查询时，返回的总条数，不是data的size
	private List<T> data;


	public JsonForList() {
	}

//	public JsonForList(String code) {
//		this.code = code;
//		switch(code) {
//			case NOT_FOUND_CODE:
//				this.msg = NOT_FOUND_MSG;
//				break;
//			case SUCCESS_CODE:
//				this.msg = SUCCESS_MSG;
//				break;
//			default:
//				break;
//		}
//	}
	public JsonForList(String code) {
		this.code = code;
		switch(code) {
			case NOT_FOUND_CODE:
				this.msg = NOT_FOUND_MSG;
				break;
			case SUCCESS_CODE:
				this.msg = SUCCESS_MSG;
				break;
			case INSERT_ERROR_CODE:
				this.msg = INSERT_ERROR_MSG;
				break;
			case UPDATE_ERROR_CODE:
				this.msg = UPDATE_ERROR_MSG;
				break;
			case DELETE_ERROR_CODE:
				this.msg = DELETE_ERROR_MSG;
				break;
			case PARAM_NOT_FOUND_CODE:
				this.msg = PARAM_NOT_FOUND_MSG;
				break;
			case SESSION_NOT_FOUND_CODE:
				this.msg = SESSION_NOT_FOUND_MSG;
				break;
//			case ResultCode.NOT_FOUND.getCode():
//			case "qwe":
//				this.msg = ResultCode.NOT_FOUND.getMessage();
			default:
				break;
		}
	}

    public JsonForList(String code,String msg) {
	    if(Strings.isNullOrEmpty(code)){
	        code = "999";//通用错误码
        }
        this.code = code;
        this.msg = msg;
    }

	public JsonForList(List<T> data, String code, String msg) {
		this.data = data;
		this.code = code;
		this.msg = msg;
	}

	public JsonForList(List<T> data) {
		this.data = data;
		this.code = SUCCESS_CODE;
		this.msg = SUCCESS_MSG;
	}

	public JsonForList(List<T> data,Integer total) {
		this.data = data;
		this.total = total;
		this.code = SUCCESS_CODE;
		this.msg = SUCCESS_MSG;
	}
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public List<T> getData() {
		return data;
	}
	public void setData(List<T> data) {
		this.data = data;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public static final String SuccessCode = "200";
	
	public static final String FailCode = "400";
}
